import petstore.persistence.user.User;
import petstore.persistence.user.UserDAOImpl;

import java.util.List;

public class JDBCDemo {
    public static void main(String[] args) {
        try
        {
            UserDAOImpl userDAO = new UserDAOImpl();
            List<User> userList = userDAO.Find_All_User();
            for(User user: userList) System.out.println(user);



//            try
//            {
//                User user = userDAO.FindUserByUsernameAndPassword("ouyangrongjia","123456");
//                System.out.println(user.toString());
//            }
//            catch (Exception e)
//            {
//                e.printStackTrace();
//            }

//            User user = new User("jack","4564",false);
//            UserDAO userDAO = new UserDAO();
//            boolean f = userDAO.InsertUser(user);
//            if(f) System.out.println("新增成功");
//            else System.out.println("新增失败");

//            Class.forName("com.mysql.cj.jdbc.Driver");
//            //通过驱动获取java到数据库的连接
//            Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mysql_test","root","123456");
//            System.out.println(connection);
//            String sql = "INSERT INTO userinfo (username,password,isadmin) VALUES ('jane','15886',0)";
//            Statement statement = connection.createStatement();
//            int row = statement.executeUpdate(sql); //返回受影响的行数
//            if(row == 1)
//            {
//                System.out.println("新增"+ row + "行，用户信息增加成功");
//            }
//            else
//            {
//                System.out.println("添加失败");
//            }
//            statement.close();
//            connection.close();

//            String sql = "SELECT * FROM userinfo";
//            Statement statement = connection.createStatement();
//            ResultSet resultSet = statement.executeQuery(sql);
//
//            if(resultSet.next())
//            {
//                int id = resultSet.getInt("user_id");
//                String username = resultSet.getString("username");
//                String password = resultSet.getString(("password"));
//                boolean isadmin = resultSet.getInt("isadmin") == 1;
//                System.out.println("id:"+ id + " username:" + username + " password:" + password + " isadmin:" + isadmin);
//            }
//            statement.close();
//            resultSet.close();
//
//            connection.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
